<template>
  <div id="app">
    <!-- 路由占位 -->
    <router-view></router-view>
    <van-tabbar v-model="activeIndex" @change="onChange">
      <van-tabbar-item icon="home-o" to="/home">首页</van-tabbar-item>
      <van-tabbar-item icon="contact" to="/member">会员</van-tabbar-item>
      <van-tabbar-item icon="cart-o" to="/shopcar" :badge="$store.state.shopcarCount">购物车</van-tabbar-item>
      <van-tabbar-item icon="search" to="/search">搜索</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
export default {
  name: 'app',
  data: function() {
    return {
      activeIndex: 0
    }
  },
  created: function() {
    this.activeIndex = parseInt(window.sessionStorage.getItem('activeIndex'))
  },
  methods: {
    /**
     * tabbar 切换事件
     */
    onChange: function() {
      window.sessionStorage.setItem('activeIndex', this.activeIndex)
    }
  }
}
</script>

<style></style>
